package com.fingard.dsp.bank.directbank.mufg01;

import java.io.*;
import java.util.Date;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.dbobj.updownfile.DownFileHelper;
import com.fingard.dsp.bank.dbobj.updownfile.DownFileRecord;
import com.fingard.dsp.bank.directbank.DirectBase;
import com.fingard.dsp.bank.reqrespobj.foreigncurrsingle.ReqForeignCurrSingle;
import com.fingard.io.FileHelper;
import com.fingard.net.WebRequest;
import com.fingard.text.StringHelper;
import com.fingard.util.TransIDHelper;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

/**
 * 三菱香港sftp
 * @version 1.0
 */
public class MUFG01Base extends DirectBase {
    protected static TransIDHelper idHelper=new TransIDHelper(1,9999);
    //解析所用到的
    protected String tag86 = ":86:";
    protected String tag34F = ":34F:";
    protected String tag90D = ":90D:";
    protected String tag90C = ":90C:";
    protected String tag13D = ":13D:";
    //配置
    //protected String splitFlag = "\r\n-";//明细分隔符
    //protected String startFlag = "{4:";//解析内容起始符号
    //protected String endFlag = "-}";//解析内容终止符号
    //86中的字符
    protected String tra = "(TRA)";
    protected String pooling = "POOLING";
    protected String ben="(BEN)";
    protected String ord = "(ORD)";
    protected String ackFlag="Status Code";
    protected String askStartFlag="Received FILE ID";
    protected String askEndFlag="Bank Reference";
    protected String timeFlag="Received Date Time";

    protected String getCharset() {
        return getBankConfig().getCharset("utf-8");
    }

    protected String getCharsetIsGbk() {
        return "GBK";
    }

    protected String amtCheck(String amt){
        if (amt.startsWith(".")) {
            amt = "0" + amt;
        }
        if (amt.endsWith(".")) {
            amt = amt + "00";
        }
        amt=keepTwoDecimals(amt);
        return amt;
    }

    /**
     * 去掉小数点后两位的任何元素
     * @param amt
     * @return
     */
    public String keepTwoDecimals(String amt){
        if(amt.indexOf(".")+3<amt.length()){
            amt=amt.substring(0,amt.indexOf(".")+3);
        }
        return amt;
    }

    /**
     * 遍历字符串最后一个字母出现的位置
     * @param str 字符串
     * @return
     */
    protected int indexLength(String str){
        char[] array = str.toCharArray();
        int indexLength=0;
        for (int i = array.length-1; i > 0; i--) {
            if (array[i] > 'a' && array[i] < 'z' || array[i] > 'A' && array[i] < 'Z') {
                indexLength=i;
                break;
            }
        }
        return indexLength;
    }

    protected void writeCommonHeader(XmlTextWriter xmlWriter) throws Exception {
        xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\""+getCharset()+"\"?>");
        xmlWriter.writeElementAttribute("Document","xmlns",
                "urn:iso:std:iso:20022:tech:xsd:pain.001.001.03\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance");
        xmlWriter.writeStartElement("CstmrCdtTrfInitn");
    }

    protected void writeFileContent(XmlTextWriter xmlWriter, ReqForeignCurrSingle reqForeignCurrSingle) throws Exception {
        xmlWriter.writeStartElement("GrpHdr");
        xmlWriter.writeElementString("MsgId", reqForeignCurrSingle.singleDetail.askNumber);
        String date = reqForeignCurrSingle.singleDetail.payDate + "T" + reqForeignCurrSingle.singleDetail.payTime;
        xmlWriter.writeElementString("CreDtTm", date);
        xmlWriter.writeElementString("NbOfTxs", "1");
        xmlWriter.writeStartElement("InitgPty");
        xmlWriter.writeEndElement();
        xmlWriter.writeEndElement();
        xmlWriter.writeStartElement("PmtInf");
        //流水号
        xmlWriter.writeElementString("PmtInfId", reqForeignCurrSingle.singleDetail.askNumber);
        xmlWriter.writeElementString("PmtMtd", "TRF");
        xmlWriter.writeStartElement("PmtTpInf");
        xmlWriter.writeStartElement("LclInstrm");
        xmlWriter.writeElementString("Prtry", "1");
        xmlWriter.writeEndElement();
        xmlWriter.writeEndElement();
        if(StringHelper.hasAnyChar(reqForeignCurrSingle.singleDetail.bookDate)){
            xmlWriter.writeElementString("ReqdExctnDt", reqForeignCurrSingle.singleDetail.bookDate);
        }else {
            xmlWriter.writeElementString("ReqdExctnDt", reqForeignCurrSingle.singleDetail.payDate);
        }
        //付款人信息
        xmlWriter.writeStartElement("Dbtr");
        /*StringBuilder addLine=new StringBuilder();//额外
        String payName=reqForeignCurrSingle.singleDetail.payName;
        if(payName.length()>66){
            xmlWriter.writeElementString("Nm", payName.substring(0,66));
            addLine.append(payName.substring(66)+" ");
        }else if(payName.length()>0){
            xmlWriter.writeElementString("Nm", payName);
        }
        String payAddr=reqForeignCurrSingle.singleDetail.payAddr;
        addressDealWith(xmlWriter,payAddr,reqForeignCurrSingle.singleDetail.payCtryCode,addLine);//付款人地址*/
        xmlWriter.writeEndElement();
        //付款账户信息
        xmlWriter.writeStartElement("DbtrAcct");
        xmlWriter.writeStartElement("Id");
        xmlWriter.writeStartElement("Othr");
        //三菱账号特殊结构
        String payAct=reqForeignCurrSingle.singleDetail.payAct;
        if(payAct.length()==10){
            payAct="68051100"+payAct;
        }else if(payAct.length()==11){
            payAct="68051200"+payAct;
        }
        xmlWriter.writeElementString("Id", payAct);
        xmlWriter.writeEndElement();
        xmlWriter.writeEndElement();
        //xmlWriter.writeElementString("Ccy", getBankConfig().getMapKeyByValue("payCurMapping",reqForeignCurrSingle.singleDetail.payAct));
        xmlWriter.writeElementString("Ccy", convertCurToBank(reqForeignCurrSingle.singleDetail.payActCur));
        xmlWriter.writeEndElement();
        //付款人银行信息
        xmlWriter.writeStartElement("DbtrAgt");
        xmlWriter.writeStartElement("FinInstnId");
        if(StringHelper.hasAnyChar(reqForeignCurrSingle.singleDetail.paySWIFTCODE)){
            xmlWriter.writeElementString("BIC", reqForeignCurrSingle.singleDetail.paySWIFTCODE);
        }
        String payCtryCode=reqForeignCurrSingle.singleDetail.payCounyeryCode;
        if("C".equals(payCtryCode)){
            payCtryCode="CN";
        }
        if(StringHelper.hasAnyChar(payCtryCode)){
            xmlWriter.writeStartElement("PstlAdr");
            xmlWriter.writeElementString("Ctry", payCtryCode);
            xmlWriter.writeEndElement();
        }
        xmlWriter.writeEndElement();
        xmlWriter.writeEndElement();
        //汇款信息
        xmlWriter.writeStartElement("CdtTrfTxInf");
        xmlWriter.writeStartElement("PmtId");
        xmlWriter.writeElementString("InstrId", reqForeignCurrSingle.singleDetail.askNumber);
        xmlWriter.writeElementString("EndToEndId", reqForeignCurrSingle.singleDetail.askNumber);
        xmlWriter.writeEndElement();
        xmlWriter.writeStartElement("Amt");
        String currency = convertCurToBank(reqForeignCurrSingle.singleDetail.payCur);//特殊情况取付款人币种
        xmlWriter.writeElementAttribute("InstdAmt",reqForeignCurrSingle.singleDetail.payAmount,"Ccy",currency);
        xmlWriter.writeEndElement();
        if(StringHelper.hasAnyChar(reqForeignCurrSingle.singleDetail.costMode)){
            xmlWriter.writeElementStringNotNull("ChrgBr", FeeBearer(reqForeignCurrSingle.singleDetail.costMode));
        }
        //中间行/代理行
        StringBuilder recAgentBnkName=new StringBuilder(reqForeignCurrSingle.singleDetail.recAgentBnkName);
        if(StringHelper.hasAnyChar(reqForeignCurrSingle.singleDetail.recAgentBnkAddr)){
            recAgentBnkName.append(" "+reqForeignCurrSingle.singleDetail.recAgentBnkAddr);
        }
        if(StringHelper.hasAnyChar(reqForeignCurrSingle.singleDetail.recAgentBnkCtryCode)){
            recAgentBnkName.append(" "+reqForeignCurrSingle.singleDetail.recAgentBnkCtryCode);
        }
        if(StringHelper.hasAnyChar(reqForeignCurrSingle.singleDetail.recAgentBnkSWIFT) || recAgentBnkName.length()>0){
            xmlWriter.writeStartElement("IntrmyAgt1");
            xmlWriter.writeStartElement("FinInstnId");
            if(StringHelper.hasAnyChar(reqForeignCurrSingle.singleDetail.recAgentBnkSWIFT)){
                xmlWriter.writeElementString("BIC", reqForeignCurrSingle.singleDetail.recAgentBnkSWIFT);
            }
            if(StringHelper.hasAnyChar(reqForeignCurrSingle.singleDetail.recAgentBnkName)){
                xmlWriter.writeElementString("Nm", reqForeignCurrSingle.singleDetail.recAgentBnkName);
            }
            String recAgentBnkCtryCode=reqForeignCurrSingle.singleDetail.recAgentBnkCtryCode;
            if(StringHelper.hasAnyChar(reqForeignCurrSingle.singleDetail.recAgentBnkAddr) || StringHelper.hasAnyChar(recAgentBnkCtryCode)){
                xmlWriter.writeStartElement("PstlAdr");
                if(StringHelper.hasAnyChar(reqForeignCurrSingle.singleDetail.recAgentBnkAddr)){
                    String recAgentBnkAddr=reqForeignCurrSingle.singleDetail.recAgentBnkAddr;
                    String agentTwnNm=recAgentBnkAddr.contains("##")?recAgentBnkAddr.substring(recAgentBnkAddr.indexOf("##")+2).replaceAll("##",""):"";
                    agentTwnNm=agentTwnNm.trim();
                    if(StringHelper.hasAnyChar(agentTwnNm)){
                        xmlWriter.writeElementString("TwnNm",agentTwnNm);
                    }
                }
                if(StringHelper.hasAnyChar(recAgentBnkCtryCode)){
                    xmlWriter.writeElementString("Ctry","C".equals(recAgentBnkCtryCode)?"CN":recAgentBnkCtryCode);
                }
                xmlWriter.writeEndElement();
            }
            xmlWriter.writeEndElement();
            xmlWriter.writeEndElement();
        }
        //收款人银行信息
        xmlWriter.writeStartElement("CdtrAgt");
        xmlWriter.writeStartElement("FinInstnId");
        if(StringHelper.hasAnyChar(reqForeignCurrSingle.singleDetail.recSWIFTCODE)){
            xmlWriter.writeElementString("BIC", reqForeignCurrSingle.singleDetail.recSWIFTCODE);
        }
        if(StringHelper.hasAnyChar(reqForeignCurrSingle.singleDetail.recBnkName)){
            xmlWriter.writeElementString("Nm", reqForeignCurrSingle.singleDetail.recBnkName);
        }
        String recCountryCode=reqForeignCurrSingle.singleDetail.recCountryCode;
        if(StringHelper.hasAnyChar(reqForeignCurrSingle.singleDetail.recBnkAddr) || StringHelper.hasAnyChar(recCountryCode)){
            xmlWriter.writeStartElement("PstlAdr");
            if(StringHelper.hasAnyChar(reqForeignCurrSingle.singleDetail.recBnkAddr)){
                String recBnkAdress=reqForeignCurrSingle.singleDetail.recBnkAddr;
                String twnNm=recBnkAdress.contains("##")?recBnkAdress.substring(recBnkAdress.indexOf("##")+2).replaceAll("##",""):"";
                twnNm=twnNm.trim();
                if(StringHelper.hasAnyChar(twnNm)){
                    xmlWriter.writeElementString("TwnNm",twnNm);
                }
            }
            if(StringHelper.hasAnyChar(recCountryCode)){
                xmlWriter.writeElementString("Ctry","C".equals(recCountryCode)?"CN":recCountryCode);
            }
            xmlWriter.writeEndElement();
        }
        xmlWriter.writeEndElement();
        xmlWriter.writeEndElement();
        //收款人信息
        xmlWriter.writeStartElement("Cdtr");
        StringBuilder addLine3=new StringBuilder();//额外
        String recName=reqForeignCurrSingle.singleDetail.recName;
        int rnLength=0;
        if(recName.length()>66){
            xmlWriter.writeElementString("Nm", recName.substring(0,66));
            addLine3.append(recName.substring(66));
            rnLength=66;
        }else if(recName.length()>0){
            xmlWriter.writeElementString("Nm", recName);
            rnLength=recName.length();
        }
        String recAddr=reqForeignCurrSingle.singleDetail.recAddr;
        String recCtryCode=reqForeignCurrSingle.singleDetail.recCtryCode;
        String addr="";
        String trwn="";
        if(StringHelper.hasAnyChar(recAddr)){
            //地址和城镇信息
            addr=recAddr.contains("##")?recAddr.substring(0,recAddr.indexOf("##")):recAddr;
            trwn=recAddr.contains("##")?recAddr.substring(recAddr.indexOf("##")+2).replaceAll("##",""):"";
            trwn=trwn.trim();
        }
        if(StringHelper.hasAnyChar(addr) || StringHelper.hasAnyChar(recCtryCode) || StringHelper.hasAnyChar(trwn)){
            xmlWriter.writeStartElement("PstlAdr");
            //总剩余长度
            int sumLength=131-rnLength-trwn.length()-2;
            //addline3剩余长度
            int adl3Length=(sumLength>=70?70:sumLength)-addLine3.length();
            //addr的长度
            addr=StringHelper.hasAnyChar(addr)?addr:"";
            int addrLength=addr.length();
            if(StringHelper.hasAnyChar(addLine3.toString())){
                if(adl3Length>=(addrLength+1)){
                    addLine3.append(" "+addr);
                }else if(adl3Length>0){
                    addLine3.append(" "+addr.substring(0,adl3Length-1));
                }
            }else {
                if(adl3Length>=addrLength){
                    addLine3.append(""+addr);
                }else if(adl3Length>0){
                    addLine3.append(""+addr.substring(0,adl3Length));
                }
            }
            if(StringHelper.hasAnyChar(trwn)){
                xmlWriter.writeElementString("TwnNm", trwn);
            }
            if(StringHelper.hasAnyChar(recCtryCode)){
                xmlWriter.writeElementString("Ctry", "C".equals(recCtryCode)?"CN":recCtryCode);
            }
            if(StringHelper.hasAnyChar(addLine3.toString())){
                xmlWriter.writeElementString("AdrLine", addLine3.toString());
            }
            xmlWriter.writeEndElement();
        }
        //addressDealWith(xmlWriter,recAddr,reqForeignCurrSingle.singleDetail.recCtryCode,addLine3);//地址
        xmlWriter.writeEndElement();
        //收款账户信息
        xmlWriter.writeStartElement("CdtrAcct");
        xmlWriter.writeStartElement("Id");
        xmlWriter.writeStartElement("Othr");
        xmlWriter.writeElementString("Id", reqForeignCurrSingle.singleDetail.recAct);
        xmlWriter.writeEndElement();
        xmlWriter.writeEndElement();
        xmlWriter.writeEndElement();
        //其它信息
        String purpose=reqForeignCurrSingle.singleDetail.purpose;
        String ustrd="";//用途
        String prtry="";//补充
        if(StringHelper.hasAnyChar(purpose)){
            if(purpose.contains("##")){
                ustrd=purpose.substring(0,purpose.indexOf("##"));
                prtry=purpose.substring(purpose.indexOf("##")+2);
            }else {
                ustrd=purpose;
            }
            if(StringHelper.hasAnyChar(prtry)){
                xmlWriter.writeStartElement("Purp");
                xmlWriter.writeElementString("Prtry",prtry);
                xmlWriter.writeEndElement();
            }
            xmlWriter.writeStartElement("RmtInf");
            xmlWriter.writeElementString("Ustrd",ustrd+(StringHelper.hasAnyChar(ustrd)?"+":"")+reqForeignCurrSingle.singleDetail.askNumber);
            xmlWriter.writeEndElement();
        }else{
            xmlWriter.writeStartElement("RmtInf");
            xmlWriter.writeElementString("Ustrd",reqForeignCurrSingle.singleDetail.askNumber);
            xmlWriter.writeEndElement();
        }
        xmlWriter.writeEndDocument();
    }

    protected String FeeBearer(String costmode){
        if("OUR".equals(costmode)){
            costmode="DEBT";
        }else if("BEN".equals(costmode)){
            costmode="CRED";
        }else if("SHA".equals(costmode)){
            costmode="SHAR";
        }
        return costmode;
    }

    /**
     * 获取ack状态并写入文件
     * @param ackFilePath
     * @param payDate
     * @param rspStatus
     * @return
     * @throws Exception
     */
    protected void getAckStatus(String ackFilePath,String payDate,String[] rspStatus,String level) throws Exception{
        String ackFile=ackFilePath+File.separator+payDate+File.separator
                + "ACK"+File.separator +rspStatus[0]+File.separator+rspStatus[0]+"_"+level+".txt";
        String contents=rspStatus[0]+"|"+rspStatus[1]+"|"+rspStatus[2]+"|";
        //写入文件
        FileHelper.appendFile(ackFile, contents, getCharset());
    }

    /**
     * 获取支持的查询日期
     * @param sDate
     * @param eDate
     * @return
     */
    protected String[] getQueryDate(String sDate,String eDate) throws Exception{
        String[] dateAry=new String[]{sDate,eDate};
        String hisTransSupDate=getBankConfig().getValueAsString("hisTransSupDate");
        //增加历史明细支持查询日期
        if (StringHelper.hasAnyChar(hisTransSupDate) && hisTransSupDate.length() == 8) {
            //判断起始日
            Date avaiDate = Format.Date8Format.parse(hisTransSupDate);
            Date startDate = Format.Date8Format.parse(dateAry[0]);
            Date endDate = Format.Date8Format.parse(dateAry[1]);
            if (endDate.after(avaiDate)) {
                if (startDate.before(avaiDate)) {
                    dateAry[0] = hisTransSupDate;
                }
            } else {
                dateAry[0] = hisTransSupDate;
                dateAry[1] = hisTransSupDate;
            }
        }
        return dateAry;
    }

    /**
     * 报文体公共部分
     * @param xmlWriter
     * @param p_bankHeader
     */
    protected void writeReqHeader(XmlTextWriter xmlWriter, MUFG01Header p_bankHeader){
        xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"" + getCharsetIsGbk() + "\" ?>");
        xmlWriter.writeStartElement("h2h");
        xmlWriter.writeStartElement("reqInfo");//请求报文头
        xmlWriter.writeElementString("transCode", p_bankHeader.transCode);//服务代码
        xmlWriter.writeElementString("pkgNo", p_bankHeader.pkgNo);//请求报文编号
        xmlWriter.writeElementString("clientCode", bankFront.keyID);//验证码
        Date date=new Date();//发送时间
        xmlWriter.writeElementString("reqTime", Format.Date10Format.format(date)+"T"+Format.Time8Format.format(date));//发送时间
        xmlWriter.writeEndElement();
    }

    /**
     * 请求银行
     * @param p_reqStr
     * @return
     * @throws Exception
     */
    protected String[] sendToBank(String p_reqStr) throws Exception {
        String[] retStr = new String[]{"", ""};
        String serverURL = "http://"+bankFront.serverIP+":"+bankFront.serverPort+"/bps/BPSService?wsdl";
        WriteBankLogLn("提交银行的地址：" + serverURL);
        WriteBankLogStep2(p_reqStr);
        StringBuffer reqMsg = new StringBuffer();
        reqMsg.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://ws.erp.bps.product.mind.com/\">\n");
        reqMsg.append(" <soapenv:Header/>\n");
        reqMsg.append(" <soapenv:Body>\n");
        reqMsg.append(" <ser:invoke>\n");
        reqMsg.append(" <requestXML>\n");
        reqMsg.append(new BASE64Encoder().encode(p_reqStr.getBytes("GBK")) + "\n");
        reqMsg.append("</requestXML>\n");
        reqMsg.append(" </ser:invoke>\n");
        reqMsg.append(" </soapenv:Body>\n");
        reqMsg.append("</soapenv:Envelope>");
        WebRequest tmpWebRequest = new WebRequest(serverURL);
        tmpWebRequest.setRequestProperty("Content-Type", "text/xml");
        tmpWebRequest.setRequestProperty("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)");
        retStr = tmpWebRequest.upload(reqMsg.toString().getBytes(getCharsetIsGbk()), getCharsetIsGbk());
        if (retStr[1] == null) {
            retStr[1] = "";
        } else {
            retStr[1]=retStr[1].substring(retStr[1].indexOf("<responseXML>")+"<responseXML>".length(),retStr[1].indexOf("</responseXML>"));
            retStr[1] = new String(new BASE64Decoder().decodeBuffer(retStr[1]), getCharsetIsGbk());
        }
        WriteBankLogStep3(retStr[1]);
        return retStr;
    }

    /**
     * 特殊字符转译
     * @param content
     * @return
     */
    public String AsciiChange(String content){
        return content.replaceAll("<","&lt;")
                .replaceAll(">","&gt;")
                .replaceAll("&","&amp;")
                .replaceAll("'","&apos;")
                .replaceAll("\"","&quot;");
    }

    public  String getQryTransID(){
        String seqNo=Format.DateTime12Year2Format.format(new Date());
        return seqNo.substring(0,8)+idHelper.getNextIDStr();
    }

    public static void main(String[] args) {
        String seqNo=Format.DateTime15Year2Format.format(new Date());
        System.out.println(seqNo.substring(1, 13));
    }

    /**
     * 回单文件生成
     * @param fileValue
     * @param fileName
     * @param localSavePath
     * @throws IOException
     */
    public static int createPdf(String fileName, String fileValue,String localSavePath) throws IOException {
        int result=0;
        FileOutputStream fos = null;
        try {
            File saveDir = new File(localSavePath);
            if (!saveDir.exists()) {
                saveDir.mkdir();
            }
            File file = new File(saveDir + File.separator + fileName);
            fos = new FileOutputStream(file);
            fos.write(new BASE64Decoder().decodeBuffer(fileValue));
            System.out.println();
            fos.flush();
            if(file.exists()){
                result=1;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fos != null) {
                fos.close();
            }
        }
        return result;
    }

    protected int insertFileRecord(DownFileRecord downRd,String tenant){
        int result=-1;
        DownFileHelper dHelper = null;
        try{
            Date nowDay = new Date();
            //此时采用当日，记录待下载文件，通过计划任务运行下载
            dHelper = new DownFileHelper(tenant, nowDay);
            int rowsAff = dHelper.insertIfNotExist(downRd);
            if(rowsAff == 1){
                result=1;
                WriteBankLogLn("记录写入成功");
            }else if(rowsAff == 0){
                result=0;
                WriteBankLogLn("记录已存在");
            }
        }catch(Exception ex){
            WriteBankLogLn(ex);
        }finally{
            if(dHelper!=null){
                dHelper.close();
            }
        }
        return result;
    }

    /**
     * 根据账号和日期查询余额
     * @param actNum
     * @param date
     * @return
     * @throws Exception
     */
    protected String getBanlce(String actNum,String date) throws Exception{
        String statusFlag="";
        //拼接请求报文体
        MUFG01Header header=new MUFG01Header();
        header.transCode="h2h.001.001";
        header.pkgNo = getQryTransID();
        XmlTextWriter xmlReq = new XmlTextWriter();
        writeReqHeader(xmlReq,header);
        xmlReq.writeStartElement("req");
        xmlReq.writeElementString("accNo",actNum);//帐号
        xmlReq.writeElementString("beginDate",date);//查询开始日期
        xmlReq.writeElementString("endDate",date);//查询结束日期
        xmlReq.writeEndDocument();
        //请求银行并获取响应结果
        String[] bankResult = sendToBank(xmlReq.toXmlString());
        //处理响应报文
        if (bankResult[0].length() == 0) {
            StringBuilder tmpSb = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(bankResult[1], tmpSb);
            if (tmpBkReader != null) {
                String acceptFlag=tmpBkReader.getFirstText("/h2h/respInfo/acceptFlag");//报文受理状态
                if("1".equals(acceptFlag)){//受理成功
                    if ("1".equals(tmpBkReader.getFirstText("/h2h/resp/statusFlag"))) {//查询处理状态 1有 -1无
                        WriteBankLogLn("查询到账户"+actNum+"在"+date+"的查询处理状态(1有 -1无)为："+tmpBkReader.getFirstText("/h2h/resp/statusFlag"));
                        statusFlag=bankResult[1];
                    }
                }
            }
        }
        return statusFlag;
    }
}
